
package brian.huang.reader;

import android.app.ActionBar;
import android.app.ActionBar.OnNavigationListener;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.SpinnerAdapter;

public class MainActivity extends Activity {

    private static final String[] LIST_VIEW_TAGS = {
            ListContentFragment.TAG_EPUB,
            ListContentFragment.TAG_TEXT,
            ListContentFragment.TAG_HISTORY
    };
    private static final String[] ACTION_ITEMS = {
            "E-Books",
            //"Text Books",
            //"History"
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // add drop-down navigation
        ActionBar actionBar = getActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
        SpinnerAdapter adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_dropdown_item,
                ACTION_ITEMS);
        OnNavigationListener callback = new OnNavigationListener() {
            public boolean onNavigationItemSelected(int itemPosition, long itemId) {
                ListContentFragment list = new ListContentFragment();
                FragmentTransaction ft = getFragmentManager().beginTransaction();
                ft.replace(R.id.list, list, LIST_VIEW_TAGS[itemPosition]);
                ft.commit();
                return false;
            }
        };
        actionBar.setListNavigationCallbacks(adapter, callback);

        actionBar.setDisplayShowTitleEnabled(false);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        Intent intent;
        switch (item.getItemId()) {
            case R.id.item_settings:
                intent = new Intent(this, PreferenceWithHeaders.class);
                startActivity(intent);
                return true;

            case R.id.item_report:
                return true;

            default:
                return super.onOptionsItemSelected(item);
        }
    }
}
